<template>
  <div>
      <el-table
    :data="tableData"
    stripe
    style="width: 100%">
    <el-table-column
      prop="number"
      label="试题编号"
      width="120">
    </el-table-column>
    <el-table-column
      prop="subject"
      label="学科"
      width="80">
    </el-table-column>
    <el-table-column
      prop="catalog"
      label="目录"
       width="80">
    </el-table-column>
    <el-table-column
      prop="questionType"
      label="题型"
       width="80">
    </el-table-column>
    <el-table-column
      prop="question"
      label="题干"
       width="280">
    </el-table-column>
    <el-table-column
      prop="addDate"
      label="录入时间"
       width="180">
    </el-table-column>
    <el-table-column
      prop="difficulty"
      label="难度"
       width="80">
    </el-table-column>
    <el-table-column
      prop="creator"
      label="录入人"
       width="80">
    </el-table-column>
    <el-table-column
      prop="chkState"
      label="审核状态"
       width="80">
    </el-table-column>
    <el-table-column
      prop="chkRemarks"
      label="审核意见"
       width="80">
    </el-table-column>
    <el-table-column
      prop="chkUser"
      label="审核人"
       width="80">
    </el-table-column>
    <el-table-column
      prop="publishState"
      label="发布状态"
       width="80">
    </el-table-column>
    <el-table-column
     fixed="right"
      label="操作"
      width="200">
       <template slot-scope="scope">
      <div class="caozuo">
      <div @click="handlePreview(scope.row)">
          <el-button type="text" >预览</el-button>
      </div>
      <div @click="handlechk(scope.row)" :disabled="true">
          <el-button type="text" :disabled="scope.row.chkState!=='待审核'">审核</el-button>
      </div>
      <div @click="handleEdit(scope.row)">
          <el-button type="text" :disabled="scope.row.publishState=='发布'">修改</el-button>
      </div>
      <div @click="handlePreview(scope.row)">
          <el-button type="text" >上架</el-button>
      </div>
      <div @click="hanleDelete(scope.row)">
         <el-button type="text">删除</el-button>
      </div>
      </div>
       </template>
    </el-table-column>
  </el-table>
  <!-- 预览弹层 -->
  <previewDialog :dialogTableVisible="dialogTableVisible" 
  :rowdata="rowdata"
  ></previewDialog>
  <el-dialog :visible="showChk" title="题目审核"  width="400px">
<el-form>
  <el-form-item>
    <el-radio v-model="formdata.chkState" label="1" checked>通过</el-radio>
    <el-radio v-model="formdata.chkState" label="2">拒绝</el-radio>
  </el-form-item>
  <el-form-item>
   <el-input type="textarea" placeholder="请输入审核意见" v-model="formdata.chkRemarks"></el-input>
  </el-form-item>
  <el-form-item class="footer">
    <el-button type="primary" @click="submit">确定</el-button>
    <el-button>取消</el-button>
  </el-form-item>
</el-form>
  </el-dialog>
  </div>
</template>


<script>
import previewDialog from '../components/preview-dialog.vue';
import {choiceCheck} from '../../api/hmmm/questions'
export default {
  props: ['tableData'],
  data() {
    return {
        rowdata:[],
        dialogTableVisible:false,
        showChk:false,
        formdata:{
          chkRemarks:undefined,
          chkState:"1",
          id:undefined
        }
    };
  },
  components: {
      previewDialog
  },
  created() {
  },
  watch: {
    newChkState:{
      
    }
  },
  computed: {
    newChkState(){
      return formdata.chkState
    }
  },
  methods: {
      //预览
      handlePreview(id){
      this.dialogTableVisible=true
      this.rowdata=id
      },
      handleEdit(data){
      this.$router.push({name:'questions-new',query:{id:data.id}})
      },
      hanleDelete(id){
          //发请求
     this.$confirm('确定删除吗').then(async()=>{
      let res= await remove(id)
      console.log(res); 
     }).catch(()=>{
         console.log('删除取消');
     })
    //  
    //  
      },
     async submit(){
       console.log(this.formdata);
        if(this.formdata.chkRemarks){
           await choiceCheck({
             id:25,
             chkState:1,
             chkRemarks:"搜索"
           })  
        }
        
      },
      handlechk(id){
        this.showChk=true
        this.formdata.id=id.id
      }
  },
};
</script>


<style lang="less" scoped>
.caozuo {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px;
  div {
    color: #409eff;
    margin: 3px;
    button {
      width: 30px;
      border: none;
      font-size: 12px;
    }
    &:hover {
      color: lightblue;
      cursor: pointer;
    }
  }
}
.el-item {
  margin: 20px;
}
.el-form-item__content {
  display: flex;
  justify-content: center;
}
</style>